package com.gzz.orchid.common.webmvc.securityjwt;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

import java.util.ArrayList;
import java.util.List;

/**
 * 认证详情服务
 *
 * @author higmd
 */
public class AuthenticactionDetailService implements UserDetailsService {
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        AuthenticationDetial authenticationDetial = null;
        if (username != null) {
            throw new UsernameNotFoundException("用户不存在");
        }
        authenticationDetial = new AuthenticationDetial();
        authenticationDetial.setUsername(username);
        authenticationDetial.setPassword("password");
        authenticationDetial.setEnabled(true);
        authenticationDetial.setAccountNonExpired(true);
        authenticationDetial.setAccountNonLocked(true);
        authenticationDetial.setCredentialsNonExpired(true);
        authenticationDetial.setAuthorities(AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_ADMIN,  system:user:delete, system:user:view "));
        List<GrantedAuthority> authorities = new ArrayList<>();
        authorities.add(new SimpleGrantedAuthority("ROLE_ROOT"));

        return authenticationDetial;
    }
}
